//
//  IFNewPatientRoundsTwoCell.m
//  Medicare
//
//  Created by admin on 2017/6/12.
//  Copyright © 2017年 medicare. All rights reserved.
//

#import "IFNewPatientRoundsTwoCell.h"
#import "DoctorInfoModel.h"

#import "IFMySchedulingPublicDefines.h"
#define proportion    kScreenWidth / 540.f
@interface IFNewPatientRoundsTwoCell ()
{
    
    CGFloat CollectionviewWeight;
    CGFloat CollectionviewHeight;
}

@end

@implementation IFNewPatientRoundsTwoCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectBtn.layer.cornerRadius = 3.0;//2.0是圆角的弧度，根据需求自己更改
    self.selectBtn.layer.borderColor = [UIColor colorWithHexString:@"23c2fva"].CGColor;//设置边框颜色
    self.selectBtn.layer.borderWidth = 1.0f;//设置边框颜色
    

    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.scrollEnabled = NO;
    [self.collectionView registerClass:[MySelectNameCollectionCell class] forCellWithReuseIdentifier:@"GradientCell"];
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    CollectionviewHeight = CGRectGetHeight(self.collectionView.frame);
    CollectionviewWeight = CGRectGetWidth(self.collectionView.frame);
    
    
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((CollectionviewWeight - 5 * 3 ) / 4.f  , 16);
}

// 设置最小列间距，也就是左行与右一行的中间最小间隔
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 5;
}

// 设置最小行间距，也就是前一行与后一行的中间最小间隔
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 10;
}

//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
//26 14
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"GradientCell";
    MySelectNameCollectionCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    DoctorInfoModel * doctorModel = self.dataArray[indexPath.row];
    cell.titleLabel.text = doctorModel.realName;
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end


@interface MySelectNameCollectionCell ()
{
    
    
    
}
@end


@implementation MySelectNameCollectionCell

- (instancetype)initWithFrame:(CGRect)frame {
    self= [super initWithFrame:frame];
    if (self) {
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame))];
        self.titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = [UIFont systemFontOfSize:13.f];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_titleLabel];
        [self addObserver:self forKeyPath:@"isSelect" options:NSKeyValueObservingOptionNew context:nil];
    }
    
    return self;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
                        change:(NSDictionary *)change context:(void *)context {
    MySelectNameCollectionCell * CollectionCell = (MySelectNameCollectionCell *)object;
    if (CollectionCell.isSelect) {
        CollectionCell.titleLabel.layer.borderColor = [UIColor colorWithHexString:@"feae7e"].CGColor;
    } else {
        CollectionCell.titleLabel.layer.borderColor = [UIColor colorWithHexString:@"d4d4d4"].CGColor;
    }
}

- (void)dealloc {
    
    [self removeObserver:self forKeyPath:@"isSelect" context:nil];
}



@end



